﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

using Weazel.Badger.Vhdl.Types;

namespace Weazel.Badger.Vhdl.Operators.Unary
{
  public class UnsignedConversion : ConversionBase
  {
    private static UnaryTypeMap[] typeMaps = new UnaryTypeMap[]
      {
       // new UnaryTypeMap(Types.Signed, Types.Unsigned),
       // new UnaryTypeMap(Types.Unsigned, Types.Unsigned),
       // new UnaryTypeMap(Types.Integer, Types.Unsigned),

        new UnaryTypeMap(Types.Types.StdLogicVector, Types.Types.Unsigned),
        new UnaryTypeMap(Types.Types.StdLogic, Types.Types.Unsigned)
      };

    public override UnaryTypeMap[] TypeMap
    {
      get
      {
        return typeMaps;
      }
    }
        
    public UnsignedConversion(int width, Types.Type from) : base(width, from)
    {     
      
    }

    public override string ToString(string expression)
    {
      if (From == Types.Types.StdLogicVector)
      {
        return string.Format("unsigned({0})", expression);
      }
      else if (From == Types.Types.StdLogic)
      {
        return string.Format("unsigned(logic_zero_ext({0}, {1}))", expression, Width);
      }
      else
      {
        string message = 
          string.Format(
            "Unsupported source type for conversion ({0})",
            From.GetType().ToString()
          );

        throw new VhdlModelException(message);
      }
    }
  }
}
